<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!--  <el-form-item label="报表名称" prop="rptName">
        <el-input
          v-model="queryParams.rptName"
          placeholder="请输入报表名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="记录时间" prop="rptTime">
        <el-date-picker
          :editable="false"
          clearable
          v-model="queryParams.rptTime"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核人" prop="auditor">
        <el-input
          v-model="queryParams.auditor"
          placeholder="请输入审核人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="操作人" prop="operator">
        <UserDialog
          @dialogChange="queryParams.operator = $event.label"
          :echoValue="queryParams.operator"
          :multiple="false"
          placeholder="请选择人员"
        />
        <!-- <el-input
          v-model="queryParams.operator"
          placeholder="请输入操作人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        /> -->
       <!-- <el-select
          v-model="queryParams.operator"
          filterable
          allow-create
          placeholder="请选择操作人"
          style="width: 100%"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in userList"
            :key="item.nickName"
            :label="item.nickName"
            :value="item.nickName"
          ></el-option>
        </el-select>-->
      </el-form-item>
      <!-- <el-form-item label="报表编码" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入报表编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="工厂名称" prop="factory">
        <el-input
          v-model="queryParams.factory"
          placeholder="请输入工厂名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="设备类型" prop="rptType">
        <el-select
          v-model="queryParams.rptType"
          placeholder="请选择设备类型"
          clearable
          size="small"
        >
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['report_bottle:bottle:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['report_bottle:bottle:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['report_bottle:bottle:remove']"
          >删除</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['report:rptrecord:export']">导出</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-s-check"
          size="mini"
          :disabled="multiple"
          @click="handleCheck"
          v-hasPermi="['report_bottle:bottle:check']"
          >审核</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="rptrecordList"
      @selection-change="handleSelectionChange"
      max-height="500"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="编号" align="center" prop="id" width="80px" />
      <!-- <el-table-column label="报表名称" align="center" prop="rptName" /> -->
      <el-table-column
        label="记录时间"
        align="center"
        prop="rptTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.rptTime, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>

      <el-table-column label="报表编码" align="center" prop="code" min-width="150px"/>
      <el-table-column label="工厂名称" align="center" prop="factory" min-width="150px"/>
      <el-table-column label="设备类型" align="center" prop="rptType" />
      <el-table-column label="操作人" align="center" prop="operator" />
      <el-table-column label="审核人" align="center" prop="auditor" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        min-width="250px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="excelhandleView(scope.row)"
          >导出</el-button            >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['report_bottle:bottle:edit']"
          >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          >

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['report_bottle:bottle:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改生产过程记录对话框 -->
    <el-dialog
      fullscreen
      :title="title"
      :visible.sync="open"
      width="700px"
      append-to-body
      custom-class="myDialog"
    >
      <TableHeader
        @nameChange="nameChange"
        @nameChange2="nameChange2"
        :data="{
          mainTitle: '吹瓶机运行记录',
          company: form.factory,
          code: form.code,
        }"
      />
      <el-form ref="form" :model="form" :rules="rules" label-width="90px">
        <el-row>
          <!--  <el-col :span="12">
                <el-form-item label="报表名称" prop="rptName">
                  <el-input v-model="form.rptName" placeholder="请输入报表名称" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <el-col :span="12">
            <el-form-item label="记录日期" prop="rptTime">
              <el-date-picker
                :editable="false"
                clearable
                size="small"
                v-model="form.rptTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="选择记录时间"
                :disabled="openDisabled"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>

          <!-- <el-col :span="12">
                <el-form-item label="报表编码" prop="code">
                  <el-input v-model="form.code" placeholder="请输入报表编码" :disabled="openDisabled" />
                </el-form-item>
            </el-col> -->
          <!-- <el-col :span="12">
                <el-form-item label="工厂名称" prop="factory">
                  <el-input v-model="form.factory" placeholder="请输入工厂名称" :disabled="openDisabled" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="设备类型" prop="rptType">
                  <el-select v-model="form.rptType" placeholder="请选择设备类型" :disabled="openDisabled">
                    <el-option label="请选择字典生成" value="" />
                  </el-select>
                </el-form-item>
            </el-col> -->
        </el-row>

        <!-- 吹瓶机运行记录信息 -->
        <br />
        <el-divider content-position="center">吹瓶机运行记录信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddRptProBottle"
              :disabled="openDisabled"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteRptProBottle"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-table
          :data="rptProBottleList"
          :row-class-name="rowRptProBottleIndex"
          @selection-change="handleRptProBottleSelectionChange"
          ref="rptProBottle"
        >
          <el-table-column type="selection" width="50" align="center" fixed />
          <!-- <el-table-column label="序号" align="center" prop="index" width="50"/> -->
          <el-table-column label="产品名称" prop="gg" minWidth="400" fixed>
            <template slot-scope="scope">
              <Dialog
                @dialogChange="dialogChange($event, scope)"
                :echoValue="scope.row.ggname"
                parameter="rows"
                value="id"
                label="name"
                :multiple="false"
                search="name/code"
                url="/basic/productInfo/listSelect"
                :column="['产成品编号/code', '产成品名称/name']"
                placeholder="请选择内容"
                :axiosData="{ typeCode: 'YYTRKQS' }"
                :openDisabled="openDisabled"
              />
            </template>
          </el-table-column>
          <el-table-column label="开机时间" prop="startTime" minWidth="110">
            <template slot-scope="scope">
              <!-- <el-date-picker
                :editable="false"
                clearable
                size="small"
                v-model="scope.row.startTime"
                type="datetime"
                value-format="yyyy-MM-dd HH:mm:ss"
                placeholder="开机时间"
                :disabled="openDisabled"
              >
              </el-date-picker> -->

              <el-time-picker
                :editable="false"
                clearable
                v-model="scope.row.startTime"
                type="time"
                format="HH:mm"
                value-format="HH:mm"
                placeholder="开机时间"
                :disabled="openDisabled"
              >
              </el-time-picker>
            </template>
          </el-table-column>
          <el-table-column label="停机时间" prop="stopTime" minWidth="110">
            <template slot-scope="scope">
              <el-time-picker
                :editable="false"
                clearable
                type="time"
                v-model="scope.row.stopTime"
                format="HH:mm"
                value-format="HH:mm"
                placeholder="停机时间"
                :disabled="openDisabled"
              >
              </el-time-picker>
            </template>
          </el-table-column>
          <el-table-column
            label="瓶坯使用数量(只)"
            prop="preformNum"
            minWidth="150"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.preformNum"
                placeholder="请输入瓶坯数量"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="瓶坯损耗数量(只)"
            prop="badNum"
            minWidth="150"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.badNum"
                placeholder="请输入瓶坯损耗数量"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="瓶盖使用数量(只)"
            prop="capNum"
            minWidth="150"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.capNum"
                placeholder="请输入瓶盖数量"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                type="primary"
                plain
                icon="el-icon-search"
                @click="handleDate(scope)"
                :disabled="openDisabled"
                >读取数据</el-button
              >
            </template>
          </el-table-column>
          <!-- <el-table-column label="报表编号" prop="bbbh">
            <template slot-scope="scope">
                <el-input v-model="scope.row.bbbh" placeholder="请输入报表编号" :disabled="openDisabled"/>
            </template>
          </el-table-column>
          <el-table-column label="报表日期" prop="bbrq">
            <template slot-scope="scope">
                <el-date-picker :editable="false" clearable size="small" v-model="scope.row.bbrq" type="date"  value-format="yyyy-MM-dd"  placeholder="选择报表日期" :disabled="openDisabled">
                </el-date-picker>
            </template>
          </el-table-column>
          <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
                <el-input v-model="scope.row.remark" type="textarea" placeholder="请输入内容" :disabled="openDisabled"/>
            </template>
          </el-table-column> -->
        </el-table>

        <!-- 吹瓶机自检记录信息 -->
        <br />
        <el-divider content-position="center">吹瓶机自检记录信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              icon="el-icon-plus"
              size="mini"
              @click="handleAddRptProBottleCheck"
              :disabled="openDisabled"
              >添加</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="handleDeleteRptProBottleCheck"
              :disabled="openDisabled"
              >删除</el-button
            >
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              icon="el-icon-delete"
              size="mini"
              @click="duplication1"
              :disabled="openDisabled"
              >复制</el-button
            >
          </el-col>
        </el-row>
        <el-divider content-position="center"></el-divider>
        <el-table
          :data="rptProBottleCheckList"
          :row-class-name="rowRptProBottleCheckIndex"
          @selection-change="handleRptProBottleCheckSelectionChange"
          ref="rptProBottleCheck"
        max-height="500"
        >
          <el-table-column type="selection" width="50" align="center" />
          <!-- <el-table-column
            label="序号"
            align="center"
            prop="index"
            width="50"
          /> -->
          <el-table-column label="检查时间" prop="jctime" width="160">
            <template slot-scope="scope">
              <el-time-picker
                :editable="false"
                clearable
                v-model="scope.row.jctime"
                type="time"
                format="HH:mm"
                value-format="HH:mm"
                placeholder="选择检查时间"
                :disabled="openDisabled"
              >
              </el-time-picker>
            </template>
          </el-table-column>

          <el-table-column label="操作" width="100px">
            <template slot-scope="scope">
              <el-button
                type="primary"
                plain
                icon="el-icon-search"
                :disabled="openDisabled"
                @click="handleDate2(scope)"
                >读取数据</el-button
              >
            </template>
          </el-table-column>
          <!-- <el-table-column label="检查项目" prop="jcxm">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.jcxm"
                placeholder="请输入检查项目"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column> -->
          <el-table-column
            :label="'前炉区温度℃'"
            style="whilt-space: pre-line"
            prop="qlqwd"
            minWidth="170px"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.qlqwd"
                placeholder="请输入前炉区温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'后炉区温度℃'" prop="hlqwd" minWidth="170px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.hlqwd"
                placeholder="请输入后炉区温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'模身出水温度℃'" prop="mscswd" minWidth="180px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.mscswd"
                placeholder="请输入模身出水温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'模身回水温度℃'" prop="mshswd" minWidth="180px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.mshswd"
                placeholder="请输入模身回水温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'底模出水温度℃'" prop="dmcswd" minWidth="180px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.dmcswd"
                placeholder="请输入底模出水温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'底模回水温度℃'" prop="dmhswd" minWidth="180px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.dmhswd"
                placeholder="请输入底模回水温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'瓶口出水温度℃'" prop="pkcswd" minWidth="180px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.pkcswd"
                placeholder="请输入瓶口出水温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'瓶口设定温度℃'" prop="pksdwd" minWidth="180px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.pksdwd"
                placeholder="请输入瓶口设定温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'坯身温度℃'" prop="pswd" minWidth="170px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.pswd"
                placeholder="请输入坯身温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column :label="'坯口温度℃'" prop="pkwd" minWidth="170px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.pkwd"
                placeholder="请输入坯口温度"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column label="高压bar" prop="gy" width="120px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.gy"
                placeholder="请输入高压"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column label="低压bar" prop="dy" width="120px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.dy"
                placeholder="请输入低压"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column
            label="洗坯空压气压力Mpa"
            prop="xpkqyl"
            width="200px"
          >
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.xpkqyl"
                placeholder="请输入洗坯空压气压力"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column label="卡坯频次" prop="kppc" width="150px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.kppc"
                placeholder="请输入卡坯频次"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column label="卡坯时长(分)" prop="kpsc" width="180px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.kpsc"
                placeholder="请输入卡坯时长(分)"
                :disabled="openDisabled"
                type="number"
              />
            </template>
          </el-table-column>
          <el-table-column label="吹瓶质量" prop="cpzl" width="150px">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.cpzl"
                placeholder="请输入吹瓶质量"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column>
          <!-- <el-table-column label="备注" prop="remark">
            <template slot-scope="scope">
              <el-input
                v-model="scope.row.remark"
                type="textarea"
                placeholder="请输入内容"
                :disabled="openDisabled"
              />
            </template>
          </el-table-column> -->
        </el-table>

        <!-- 审核 -->
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input
              v-model="form.remark"
              type="textarea"
              placeholder="请输入内容"
              :disabled="openDisabled"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="审核人" prop="auditor">
            <el-input
              v-model="form.auditor"

              :disabled="true"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="操作人" prop="operator">
            <UserDialog
              @dialogChange="form.operator = $event.label"
              :echoValue="form.operator"
              :multiple="false"
              :openDisabled="openDisabled"
              placeholder="请选择人员"
            />
            <!-- <el-input
              v-model="form.operator"
              placeholder="请输入操作人"
              :disabled="openDisabled"
            /> -->
            <!-- <el-select
              v-model="form.operator"
              placeholder="请选择操作人"
              style="width: 100%"
            >
              <el-option
                v-for="item in userList"
                :key="item.nickName"
                :label="item.nickName"
                :value="item.nickName"
              ></el-option>
            </el-select> -->
<!--            <el-select
              v-model="form.operator"
              filterable
              allow-create
              placeholder="请选择操作人"
              style="width: 100%"
              :disabled="openDisabled"
            >
              <el-option
                v-for="item in userList"
                :key="item.nickName"
                :label="item.nickName"
                :value="item.nickName"

              ></el-option>
            </el-select>-->
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!openDisabled">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listRptrecord,
  getRptrecord,
  delRptrecord,
  addRptrecord,
  updateRptrecord,
  checkRptrecord,
  handleDate,
  handleDate2,
} from "@/api/report/process/bottle";
import { getInfo } from "@/api/login";
import { listUser } from "@/api/system/user";

export default {
  name: "Rptrecord",
  data() {
    return {
      /* 当前用户名 */
      nickName: "",
      userList: [],
      //弹窗是否禁止编辑
      openDisabled: true,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedRptProBottleCheck: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 生产过程记录表格数据
      rptrecordList: [],
      // 吹瓶机运行记录表格数据
      rptProBottleCheckList: [],
      rptProBottleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 50,
        rptName: null,
        rptTime: null,
        rptTime1: null,
        auditor: null,
        operator: null,
        code: null,
        factory: null,
        rptType: "吹瓶机",
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.queryUserList();
    this.getDicts("report_bottle_cpmc").then((response) => {
      this.report_bottle_cpmc = response.data;
    });
  },
  methods: {
    // 复制最后一行
    duplication1() {
      let arr = this.rptProBottleCheckList;
      let obj = arr[arr.length - 1];
      var obj1 = JSON.parse(JSON.stringify(obj));
      this.rptProBottleCheckList.push(obj1);
    },
    // 读取数据
    handleDate(scope) {
      // console.log(scope);
      if (this.form.rptTime == "" || this.form.rptTime == null) {
        this.msgError("请输入记录日期");
      } else {
        const start = scope.row.startTime;
        const end = scope.row.stopTime;
        const start1 = this.form.rptTime + " " + start;
        const end1 = this.form.rptTime + " " + end;

        if (start == "" || start == null) {
          this.msgError("请输入开始时间");
        } else if (end == "" || end == null) {
          this.msgError("请输入结束时间");
        } else {
          // 调取接口
          handleDate({
            startTime: start1 + ":00",
            stopTime: end1 + ":00",
          }).then((res) => {
            this.rptProBottleList[scope.$index].preformNum =
              res.data.preformNum;
            this.rptProBottleList[scope.$index].capNum = res.data.capNum;
          });
        }
      }
    },
    handleDate2(scope) {
      // console.log(scope);

      if (this.form.rptTime == "" || this.form.rptTime == null) {
        this.msgError("请输入记录日期");
      } else {
        const jc = scope.row.jctime;
        const date = this.form.rptTime + " " + jc;
        if (jc == "" || jc == null) {
          this.msgError("请输入检查时间");
        } else {
          let startTime = "";
          let l = this.rptProBottleCheckList.length;
          if (l == 1) {
            startTime = date + ":00";
          } else if (this.rptProBottleCheckList[l - 1].jctime != "") {
            startTime = this.form.rptTime + " " + this.rptProBottleCheckList[l - 1].jctime + ":00";
          }

          // 调取接口
          handleDate2({ startTime: startTime, jctime: date + ":00" }).then(
            (res) => {
              this.rptProBottleCheckList[scope.$index].qlqwd = Number(
                res.data.qlqwd
              ).toFixed(1);
              this.rptProBottleCheckList[scope.$index].hlqwd = Number(
                res.data.hlqwd
              ).toFixed(1);
              this.rptProBottleCheckList[scope.$index].pswd = Number(
                res.data.pswd
              ).toFixed(1);
              this.rptProBottleCheckList[scope.$index].pkwd = Number(
                res.data.pkwd
              ).toFixed(1);
              this.rptProBottleCheckList[scope.$index].gy = Number(
                res.data.gy
              ).toFixed(1);
              this.rptProBottleCheckList[scope.$index].dy = Number(
                res.data.dy
              ).toFixed(1);
              // this.rptProBottleCheckList[scope.$index].xpkqyl = res.data.xpkqyl;
              this.rptProBottleCheckList[scope.$index].kppc = Number(
                res.data.kppc
              ).toFixed(1);
              this.rptProBottleCheckList[scope.$index].kpsc = Number(
                res.data.kpsc
              ).toFixed(1);
            }
          );
        }
      }
    },
    dialogChange(event, scope) {
      let flag = true;
      // for(let r=0;r<this.rptProBottleList.length;r++){
      //   let temp=this.rptProBottleList[r];
      //   if(event.options.code == temp.gg){
      //     this.msgSuccess("该产品已存在,请勿重复添加！");
      //     flag = false;
      //   }
      // }
      if(flag){
        this.rptProBottleList[scope.$index].gg = event.options.code;
        this.rptProBottleList[scope.$index].ggname = event.label;
      }else{
        // console.log(this.rptProBottleList);
        this.rptProBottleList.pop();
      }
    },
    /** 查询生产过程记录列表 */
    getList() {
      this.loading = true;
      listRptrecord(this.queryParams).then((response) => {
        this.rptrecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        rptName: "生产过程记录",
        rptTime: null,
        auditor: null,
        operator: this.nickName,
        code: "LK-QF-LS1-10-013-12-01",
        factory: "青岛崂山矿泉水有限公司",
        rptType: "吹瓶机",
        delFlag: null,
        remark: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
      };
      this.rptProBottleCheckList = [];
      this.rptProBottleList = [];
      this.resetForm("form");

      const myDate = new Date();
      const year = myDate.getFullYear();
      const month = myDate.getMonth() + 1;
      const day = myDate.getDate();
      this.form.rptTime = `${year}-${month}-${day}`;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if (this.queryParams.rptTime != null) {
        let arr = this.queryParams.rptTime;
        this.queryParams.rptTime = arr[0];
        this.queryParams.rptTime1 = arr[1];
      }

      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openDisabled = false;
      this.open = true;
      this.title = "添加生产过程记录";
      // 添加一条数据
      this.handleAddRptProBottle();
    },
    /** 吹瓶机运行记录删除按钮操作 */
    handleDeleteRptProBottle() {
      if (this.checkedRptProBottle.length == 0) {
        this.$alert("请先选择要删除的吹瓶机运行记录数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.rptProBottleList.splice(this.checkedRptProBottle[0].index - 1, 1);
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.openDisabled = false;
      const id = row.id || this.ids;
      getRptrecord(id).then((response) => {
        this.form = response.data;
        this.rptProBottleCheckList = response.data.rptProBottleCheckList;
        this.rptProBottleList = response.data.rptProBottleList;
        this.open = true;
        this.title = "修改生产过程记录";
      });
    },
    /** 查看按钮 */
    handleView(row) {
      this.reset();
      this.openDisabled = true;

      this.handleAddRptProBottle();

      const id = row.id || this.ids;
      getRptrecord(id).then((response) => {
        this.form = response.data;
        this.rptProBottleCheckList = response.data.rptProBottleCheckList;
        this.rptProBottleList = response.data.rptProBottleList;
        this.open = true;
        this.title = "查看生产过程记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.rptProBottleCheckList = this.rptProBottleCheckList;
          this.form.rptProBottleList = this.rptProBottleList;
            /**打开遮罩层*/
            const rLoading = this.openLoading();
          if (this.form.id != null) {
            updateRptrecord(this.form)
              .then((response) => {
                /**成功后执行关闭遮罩层*/
                rLoading.close();
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              })
              .catch((error) => {
                /**请求异常后执行关闭遮罩层*/
                rLoading.close();
              });
          } else {
            addRptrecord(this.form)
              .then((response) => {
                /**成功后执行关闭遮罩层*/
                rLoading.close();
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              })
              .catch((error) => {
                rLoading.close();
              });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm(
        '是否确认删除生产过程记录编号为"' + ids + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delRptrecord(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 吹瓶机运行记录序号 */
    rowRptProBottleCheckIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 吹瓶机自检记录添加按钮操作 */
    handleAddRptProBottleCheck() {
      let obj = {};
      obj.jctime = null;
      obj.jcxm = "";
      obj.qlqwd = "";
      obj.hlqwd = "";
      obj.mscswd = "";
      obj.mshswd = "";
      obj.dmcswd = "";
      obj.dmhswd = "";
      obj.pkcswd = "";
      obj.pksdwd = "";
      obj.pswd = "";
      obj.pkwd = "";
      obj.gy = "";
      obj.dy = "";
      obj.xpkqyl = "";
      obj.kppc = "";
      obj.kpsc = "";
      obj.cpzl = "正常";
      obj.remark = "";
      this.rptProBottleCheckList.push(obj);
    },
    /** 吹瓶机运行记录序号 */
    rowRptProBottleIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 吹瓶机运行记录添加按钮操作 */
    handleAddRptProBottle() {
      let obj = {};
      obj.gg = "";
      obj.ggname = "";
      obj.startTime = null;
      obj.stopTime = null;
      obj.preformNum = "";
      obj.badNum = "";
      obj.capNum = "";
      obj.bbbh = "";
      obj.bbrq = "";
      obj.remark = "";
      this.rptProBottleList.push(obj);
    },
    /** 单选框选中数据 */
    handleRptProBottleSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.rptProBottle.clearSelection();
        this.$refs.rptProBottle.toggleRowSelection(selection.pop());
      } else {
        this.checkedRptProBottle = selection;
      }
    },
    /** 吹瓶机运行记录删除按钮操作 */
    handleDeleteRptProBottleCheck() {
      if (this.checkedRptProBottleCheck.length == 0) {
        this.$alert("请先选择要删除的吹瓶机运行记录数据", "提示", {
          confirmButtonText: "确定",
        });
      } else {
        this.rptProBottleCheckList.splice(
          this.checkedRptProBottleCheck[0].index - 1,
          1
        );
      }
    },
    /** 单选框选中数据 */
    handleRptProBottleCheckSelectionChange(selection) {
      if (selection.length > 1) {
        this.$refs.rptProBottleCheck.clearSelection();
        this.$refs.rptProBottleCheck.toggleRowSelection(selection.pop());
      } else {
        this.checkedRptProBottleCheck = selection;
      }
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "report/bottle/export",
        {
          ...this.queryParams,
        },
        "生产过程记录" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    excelhandleView(row){
      this.download(
        "productionProcess/bottle/exportexcel?id="+row.id,
        {
          ...this.queryParams,
        },
        "吹瓶机过程记录" + this.parseTime(new Date()) + ".xlsx"
      );
    },
    //接收编号
    nameChange(e) {
      this.form.bbbh = e;
    },
    nameChange2(e) {
      this.form.factory = e;
    },
    /** 审核按钮操作 */
    handleCheck(row) {
      /* 审核 */
      this.ids.forEach((id) => {
        getRptrecord(id).then((response) => {
          // console.log(response.data.auditor)
          if (response.data.auditor != null && response.data.auditor != "") {
            this.msgError(
              '编号为"' + id + '"的数据项已审核完成，无需重复审核！'
            );
          } else {
            let obj = {};
            obj.id = id;
            obj.auditor = this.nickName;
            obj.rptProBottleCheckList = this.rptProBottleCheckList;
            obj.rptProBottleList = this.rptProBottleList;
            /* 修改 */
              checkRptrecord(obj).then((response) => {
              this.msgSuccess('编号为"' + id + '"的数据项审核成功！');
              this.getList();
            });
          }
        });
      });
    },
    /* 查询用户列表 */
    queryUserList() {
      listUser().then((response) => {
        this.userList = response.rows;
      });
      getInfo().then((response) => {
        this.nickName = response.user.nickName;
      });
    },
  },
};
</script>
<style>
.el-table .cell {
  white-space: pre-line;
}

</style>
